<template>
    <div class="app">
        <el-main class="Search ">
            <div style="display:flex;justify-content: space-between;">
                <i class="el-icon-search">筛选搜索</i>
                <div>
                    <el-button size="medium">重置</el-button>
                    <el-button type="primary" size="medium" @click="Inquire()">查询结果</el-button>
                </div>
            </div>

            <div class="Inquires">
                <div class="Inquire"> <span style="width: 85px;">输入搜索</span>
                    <el-input v-model="input" placeholder="商品名称"></el-input>
                </div>
                <div class="Inquire"> <span style="width: 85px;">商品货号</span>
                    <el-input v-model="input1" placeholder="商品货号"></el-input>
                </div>
                <div class="Inquire"> <span>商品分类</span>

                    <el-cascader v-model="value" :options="option" @change="handleChange" :props="{
                        expandTrigger: 'hover',
                        value: 'categoryId',
                        label: 'categoryName'
                    }"></el-cascader>

                </div>
            </div>
            <!-- //商品品牌 -->
            <div class="Inquires">
                <div class="Inquire">
                    <div class="Inquire"> <span>商品品牌</span>
                        <el-cascader v-model="value1" :options="option1" />
                    </div>
                </div>
                <div class="Inquire">
                    <span>上架状态</span>
                    <el-cascader v-model="value2" :options="option2" />
                </div>
                <div class="Inquire">
                    <span>审核状态</span>
                    <el-cascader v-model="value3" :options="option3" />
                </div>
            </div>

        </el-main>

        <el-main class="add">
            <div>
                <i class="el-icon-s-management">数据列表</i>
            </div>
            <el-button plain>添加</el-button>
        </el-main>
        <!-- 数据 -->
        <el-main class="data">
            <el-table ref="multipleTable" :data="Arr" tooltip-effect="dark" style="width: 100%"
                @selection-change="handleSelectionChange">
                <!-- <template v-for="element in Arr"> -->

                <el-table-column type="selection" width="55">
                </el-table-column>
                <el-table-column label="编号" width="120" prop="productId">
                    <!-- <template slot-scope="scope">{{element.categoryId}}</template> -->
                </el-table-column>
                <el-table-column label="商品图片" width="120">
                    <!-- <img :src="require(`@/static/${item.productSrc}`)" alt=""> -->
                    <template v-slot:default="scope">
                        <el-image :src="scope.row.productSrc" />
                    </template>
                </el-table-column>
                <el-table-column prop="text" label="商品名称">
                </el-table-column>
                <el-table-column prop="product" label="价格/货号">
                </el-table-column>
                <el-table-column label="标签">
                    <el-switch v-model="valueS" active-color="blue" inactive-color="#ff4949" inactive-text="上架">
                    </el-switch>
                    <el-switch v-model="valueS" active-color="blue" inactive-color="#ff4949" inactive-text="新品">
                    </el-switch>
                    <el-switch v-model="valueS" active-color="blue" inactive-color="#ff4949" inactive-text="推荐">
                    </el-switch>
                </el-table-column>
                <el-table-column prop="" label="sku库存">
                    <el-button type="primary" icon="el-icon-edit" circle></el-button>
                </el-table-column>
                <el-table-column prop="Sales" label="排序">
                </el-table-column>
                <el-table-column prop="Sales" label="销量">
                </el-table-column>
                <el-table-column prop="Audit" label="审核状态">
                    <p>未审核</p>
                    <p style="color:blue">审核详情</p>
                </el-table-column>

                <el-table-column prop="  operate" label="操作">
                    <template slot-scope="scope">
                        <el-button size="small">查看</el-button>
                        <el-button size="small" @click="upData(scope.row)">编辑</el-button>
                        <el-button size="small">日志</el-button>

                        <el-button type="danger" size="small" @click="checkDetail(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
                <!-- </template> -->

            </el-table>
        </el-main>

    </div>
</template>
<script>
export default {
    name: 'productList',
    data() {
        return {
            input: '',//输入搜索
            input1: '',//商品货号
            value: '',//商品分类
            value1: '',//商品品牌
            value2: 0,//上架状态
            value3: 0,//审核状态
            valueS: true,
            // Arr: [{}],
            Arr: [],

            //商品分类
            option: [
                // {
                //     value: '服装',
                //     label: '服装',
                //     children: [
                //         {
                //             value: '上衣',
                //             label: '上衣'
                //         },

                //     ],

                // }, {
                //     value: '数码',
                //     label: '数码',
                //     children: [
                //         {
                //             value: '手机',
                //             label: '手机'
                //         }, {
                //             value: '笔记本电脑',
                //             label: '笔记本电脑'
                //         },

                //     ]
                // }
            ],
            //商品品牌
            option1: [
                {
                    value: '华为',
                    label: '华为',

                }
            ],
            //上架状态
            option2: [
                {
                    value: '上架',
                    label: '上架',

                }, {
                    value: '下架',
                    label: '下架'
                }
            ],
            //审核状态
            option3: [
                {
                    value: '审核通过',
                    label: '审核通过',

                }, {
                    value: '未审核',
                    label: '未审核'
                }
            ],
            //数据
            tableData: [{

            }]
        }
    },
    methods: {
        toggleSelection(rows) {
            if (rows) {
                rows.forEach(row => {
                    this.$refs.multipleTable.toggleRowSelection(row);
                });
            } else {
                this.$refs.multipleTable.clearSelection();
            }
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        //查询数据
        Inquire() {
            this.$axios.get('/product/list', {
                params: {
                    proDuctName: this.input,
                    categoryId:this.value[1]

                }
            })
                .then((res) => {
                    this.Arr = res.data
                    console.log(res.data, this.Arr);
                }).catch(err => {
                    console.log(err, 'err')
                });
        },
        //删除数据
        checkDetail(val) {
            this.$axios.post('/product/delete', {
                productId: val.productId
            })
                .then((res) => {
                    this.Arr = res.data
                    console.log(res);
                }).catch(err => {
                    console.log(err, 'err')
                });
        },
        //商品分类
        handleChange() {

        },
        upData(val) {
            let Sales = val.Sales = 10000000
            console.log(val)
            this.$axios.post('/product/update', {
                Sales: Sales,
                productId: val.productId
            })
                .then((res) => {
                    console.log(val)
                    this.Arr = res.data
                    console.log(res);
                }).catch(err => {
                    console.log(err, 'err')
                });
        }

    },
    //一开始获取数据
    beforeCreate() {
        this.$axios.get('/product/list', {

        })
            .then((res) => {

                this.Arr = res.data
                console.log(res.data, this.Arr);
            }).catch(err => {
                console.log(err, 'err')
            });
        this.$axios.get('/product/category', {

        }).then((res) => {
              this.option=res.data
        }).catch(err => {
                console.log(err, 'err')
            });
    }
}
</script>
<style lang="less" scoped>
* {
    margin: 0;
    padding: 0;
}

.clearfix::after {
    content: "";
    display: table;
    clear: both
}

.Search {
    border: solid #eee thin;

    // background-color: red;
    .Inquires {
        display: flex;
        justify-content: space-between;

        .Inquire {
            margin: 10px;
            display: flex;

            span {
                display: block;
                //   width: 90px;
            }
        }

    }
}

.add {
    border: solid #eee thin;
    margin-top: 20px;
    display: flex;
    justify-content: space-between;

    div {
        margin: 10px;
    }

    .el-button {
        margin: 10px;
    }
}

.data {
    margin-top: 10px;
}
</style>